package cn.com.zero.manager.auth.controller;

import cn.com.zero.api.log.annotation.Log;
import cn.com.zero.base.vo.ResponseVO;
import cn.com.zero.manager.auth.constant.LogType;
import cn.com.zero.manager.auth.service.IManageOnlineService;
import cn.com.zero.manager.auth.vo.OnlineManagerVO;
import cn.com.zero.web.controller.BaseController;
import io.swagger.annotations.*;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author Huangyong
 * @version 1.0.0
 * @Description
 * @createTime 2020/1/16 9:17
 */
@Api(tags = "在线管理员管理接口")
@Validated
@RestController
@RequestMapping("/manager/managerOnline")
public class ManageOnlineController extends BaseController {

    /**
     * 在线管理员管理service
     */
    private IManageOnlineService manageOnlineService;

    @ApiOperation("查询在线管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户编号"),
            @ApiImplicitParam(paramType = "query", name = "nickname", value = "名称"),
            @ApiImplicitParam(paramType = "query", name = "showMobilePhone", value = "手机号"),
            @ApiImplicitParam(paramType = "query", name = "beginTime", value = "开始时间;格式:yyyy-MM-dd"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间;格式:yyyy-MM-dd"),
            @ApiImplicitParam(paramType = "query", name = "loginClient", value = "登录设备：1：pc-web 2：android 3：ios 4：mobile-web")
    })
    @GetMapping("/list")
    public List<OnlineManagerVO> queryOnlineCustomer(@RequestParam(value = "userId", required = false) String userId
            , @RequestParam(value = "nickname", required = false) String nickname
            , @RequestParam(value = "showMobilePhone", required = false) String showMobilePhone
            , @RequestParam(value = "beginTime", required = false) Date beginTime
            , @RequestParam(value = "endTime", required = false) Date endTime
            , @RequestParam(value = "loginClient", required = false)
                  @Range(min = 1, max = 4, message = "登录设备标识为非法数字")Integer loginClient) {

        return manageOnlineService.queryOnlineCustomer(userId,nickname,showMobilePhone,beginTime,endTime,loginClient);
    }

    @Log(content = "下线管理员", logType = LogType.LOG_MANAGE)
    @ApiOperation(value = "下线管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "userId", value = "用户Id，当传入用户Id未登录时返回 false，已登录，且强制下线成功返回 true"),
            @ApiImplicitParam(paramType = "query", name = "loginClient", value = "登录设备：1：pc-web 2：android 3：ios 4：mobile-web")
    })
    @ApiResponse(code = 200, message = "返回boolean true 成功 false 失败")
    @PostMapping("/kickoff/{userId}")
    public ResponseVO kickoff(@PathVariable("userId") String userId,
                              @RequestParam(value = "loginClient")
                              @Range(min = 1, max = 4, message = "登录设备标识为非法数字")Integer loginClient) {
        ResponseVO result = new ResponseVO();
        result.setData(manageOnlineService.kickoff(userId,loginClient));
        return result;
    }

    @Autowired
    public void setManageOnlineService(IManageOnlineService manageOnlineService) {
        this.manageOnlineService = manageOnlineService;
    }
}
